//
//  JXHUserAccontModel.swift
//  JXHSinaWeiBo
//
//  Created by juxiaohui on 16/10/20.
//  Copyright © 2016年 juxiaohui. All rights reserved.
//

import UIKit

class JXHUserAccontModel: NSObject,NSCoding{
    
    
    // MARK: - 保存属性
    
    /// token
    var access_token : String?
    /// uid
    var uid  : String?
    /// 过期日期
    var expires_in  = 0.0 {
    
        didSet{
            expiresDate = Date.init(timeIntervalSinceNow: expires_in)
        }
    }
    
    var expiresDate : Date?
    
    /// 昵称
    var screen_name : String?
    
    ///头像
    var avatar_large : String?
    
    
    
    init(dic : [String : Any]) {
        super.init()
        setValuesForKeys(dic)
    }
    
    //重写setValueforUndefinedKey
    override func setValue(_ value: Any?, forUndefinedKey key: String) {}
//
    //重写属性
    
//    override var description: String {
//    
//        return
//    }
    
    
    /// 接档
    required init?(coder aDecoder: NSCoder) {
        access_token =   aDecoder.decodeObject(forKey: "access_token") as? String
        uid          =   aDecoder.decodeObject(forKey: "uid") as? String
        expiresDate  =   aDecoder.decodeObject(forKey: "expiresDate") as? Date
        screen_name  =   aDecoder.decodeObject(forKey: "screen_name") as? String
        avatar_large =   aDecoder.decodeObject(forKey: "avatar_large") as? String
    }
    
    /// 归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(expiresDate, forKey: "expiresDate")
        aCoder.encode(screen_name, forKey: "screen_name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
    }
}


